package com.zoro.barn.business.service.system.business.team.service;

import com.zoro.barn.business.service.system.business.team.dao.BarnTeamMapper;
import com.zoro.barn.business.service.system.business.team.entity.BarnTeam;
import com.zoro.barn.business.service.system.business.team.entity.BarnTeamUserDto;
import com.zoro.barn.commons.tools.string.IDs;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import jakarta.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author zhaoxingwu
 */
@Service
public class BarnTeamService {

    @Resource
    private BarnTeamMapper barnTeamMapper;

    /**
     * query by multiple conditions
     *
     * @param param param
     * @return result set
     */
    public List<BarnTeam> query(BarnTeam param) {
        return this.barnTeamMapper.query(param);
    }

    /**
     * query by pid
     *
     * @param pid pid
     * @return result
     */
    public BarnTeam getById(String pid) {
        return this.barnTeamMapper.getById(pid);
    }

    /**
     * 插入新数据
     *
     * @param team new data
     * @return saved data
     */
    @Transactional
    public BarnTeam insert(BarnTeam team) {
        team.setPid(IDs.uuid());
        team.setCreateTime(new Date());
        barnTeamMapper.insert(team);
        return team;
    }

    /**
     * update a data by pid
     *
     * @param team data
     * @return saved data
     */
    @Transactional
    public BarnTeam update(BarnTeam team) {
        team.setUpdateTime(new Date());
        barnTeamMapper.update(team);
        return team;
    }

    /**
     * 查询某个角team 的用户
     *
     * @param userDto {@link BarnTeamUserDto}
     * @return result
     */
    public List<BarnTeamUserDto> getUsers(BarnTeamUserDto userDto) {
        return this.barnTeamMapper.getUsers(userDto);
    }
}
